<template>
	<view class="wrap">
		<js-error mode="bottom" ref="jsError"></js-error>
		<view class="cu-bar bg-white ">
			<view class="action">
				<u-icon name="/static/image/invcode.png" size="80"></u-icon>
				<text class="cuIcon-titles text-bold">到货信息</text> 
			</view>
		</view>
		<u-form class="form bg-white" :model="model"  ref="uForm" label-position="left" style="margin-top: -20px;">
			<u-form-item label="车次:" prop="carNo" label-width="230" :label-style="{'font-weight':'bold'}">
				<u-input placeholder="" v-model="model.djNo" type="text" :disabled="true" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="车牌号:" prop="carNo" label-width="230" required :label-style="{'font-weight':'bold'}">
				<!-- <u-input placeholder="" v-model="model.carNo" type="text"  di maxlength="64"></u-input> -->
				<xm-cell special label="" :value="model.carNo" @show="showKeyboard('xmKeyboard')"></xm-cell>
				<!-- 虚拟键盘载体 -->
				<xm-keyboard-v2 ref="xmKeyboard" @confirm="(v) => model.carNo = v"></xm-keyboard-v2>
			</u-form-item>
			<u-form-item label="计划到货日期" prop="time" label-width="230" required :label-style="{'font-weight':'bold'}">
			    <u-input placeholder="" v-model="model.planDate" type="select" :select-open="pickerTime" @click="pickerTime = true"></u-input>
			</u-form-item>
			<u-picker mode="time" v-model="pickerTime" @confirm="timeConfirm" :params="params"></u-picker>
			<u-form-item label="司机:" prop="cdriver" label-width="230" :label-style="{'font-weight':'bold'}">
				<u-input placeholder="" v-model="model.cdriver" type="text"  di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="司机电话:" prop="driverPhone" label-width="230" :label-style="{'font-weight':'bold'}">
				<u-input placeholder="" v-model="model.driverPhone" type="text"  di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="运输单位:" prop="testCarVen" label-width="230" required :label-style="{'font-weight':'bold'}">
				<js-select v-model="model.carVenCode" :showFilter="true" :items="carVenSelectList"  placeholder="" :tree="true"
					:label-value="model.carVenName" @label-input="model.carVenName = $event"></js-select>
			</u-form-item>
			<u-form-item label="是否再次上传:" prop="ipicture" label-width="230" required :label-style="{'font-weight':'bold'}">
				<js-radio v-model="model.ipicture" dict-type="sys_yes_no"></js-radio>
			</u-form-item> 
			<u-form-item label="备注:" prop="remarks" label-width="230" :label-style="{'font-weight':'bold'}">
				<u-input placeholder="" v-model="model.remarks" type="text"  di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="上传图片（选填）" prop="images" label-position="top" :label-style="{'font-weight':'bold'}">
				<js-uploadfile v-model="model.dataMap" imageMaxWidth="-1" imageMaxHeight="-1" :biz-key="model.id" biz-type="carplanDhH_image"></js-uploadfile>
			</u-form-item>
		</u-form>
		<!-- <view class="form-footer b-btns">
			<view class="footer">
				<u-button class="btn" type="primary" @click="submit">保存</u-button>
			</view>
		</view> -->
		<view style="height: 60px;"></view>
		<view class="btn-group cu-bar foot">
			<button class="cu-btn bg-green shadow-blur" @tap="submit()">
				<text class="cuIcon-add"></text> 保存
			</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model:{
					// id:'',
					// carNo:'',
					// planDate:'',
					// cdriver:'',
					// driverPhone:'',
					// carVenCode:'',
					// carVenName:'',
					// remarks:'',
				},
				carVenSelectList: [],
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: true
				},
				pickerTime: false,//控制日期显示
			}
		},
		onLoad(params){
			this.model = JSON.parse(params.model)
		},
		onShow() {
		},
		onReady() {
			// 运输单位数据
			this.$u.api.carVen.treeData().then(res => {
				this.carVenSelectList = res;
			});
		},
		methods: {
			showKeyboard(ref){
				this.$refs[ref].toShow(this.model.carNo)
			},
			timeConfirm(e){
				this.model.planDate = e.year + '-' + e.month + '-' + e.day +' '+e.hour +":"+e.minute +":"+e.second;
			},
			submit(data, callback) {
				if(this.model.carNo == null || this.model.carNo == ''){
					// this.$u.toast('请正确填入车牌号！');
					this.$refs.jsError.showError('','请正确填入车牌号！','error');
					return;
				}else if(this.model.planDate == null || this.model.planDate == ''){
					this.$refs.jsError.showError('','请正确选择计划到货日期！','error');
					return;
				}else if(this.model.carVenCode == null || this.model.carVenCode == ''){
					this.$refs.jsError.showError('','请正确选择运输单位！','error');
					return;
				}else if(this.model.ipicture == undefined || this.model.ipicture == ''){
					this.$refs.jsError.showError('','请必填图片是否可再次上传！','error');
					return;
				}else{
					var data = {
						mfCarplanDhH: JSON.stringify(this.model),
						useStatus: 1
					};
					this.$u.api.mfsh.save(data).then(res => {
						if(res.result == 'true'){
							this.$u.toast(res.message);
							setTimeout(()=>{
								uni.$emit('refreshData');
								uni.navigateBack({
									delta: 1
								})
							},500)
						}else{
							this.$refs.jsError.showError('',res.message,'error');
						}
					});
				}
			},
		}
	}
</script>
<style scoped  lang="less">
/* .footer {
	position: fixed;
	left: 0;
	bottom: 20px;
	width: 100%;
	
} */

.cu-bar {
		min-height: 60px;
	}

	.cu-btn {
		font-size: 16px;
		height: 40px;
	}

	.foot {
		background: #fff;
	}

	.cu-item {
		flex-wrap: wrap;
		padding: 8px 15px !important;
	}

	.title {
		width: 220rpx;
	}

	.cu-modal-slot {
		margin: 42rpx 32rpx 20rpx 32rpx;
		height: 100vh;
		position: relative;
	}

	.cu-modal-header {
		font-size: 38rpx;
		color: #3d3d3d;
		line-height: 40rpx;
		text-align: left;
		font-weight: 500;
	}

	.button {
		font-size: 32rpx;
		color: #666666;
		line-height: 40rpx;
		padding: 12rpx 40rpx;
		margin-bottom: 20rpx;
		background: #e2e2e2;
		border-radius: 180rpx;
	}

	.button:hover {
		background: #3e97b0;
		color: #ffffff;
	}

	.cu-modal-search-title {
		margin: 32rpx 0rpx 20rpx 0rpx;
		text-align: left;
		font-size: 32rpx;
		color: #999999;
		line-height: 40rpx;
	}

	.cu-dialog {
		background: #ffffff;
	}

	.cu-modal-footer {
		padding: 32rpx 32rpx;
		width: 100%;

		.cu-btn {
			width: 50%;
		}
	}

	.bg-confirm {
		background: #3e97b0;
		color: #ffffff;
	}
</style>